package com.substation.utils;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import com.substation.R;

/**
 * Created by wangbing on 2017/12/6.
 * 初始化操作
 */

public class AppInit implements Application.ActivityLifecycleCallbacks {

    private Application application;
    private static AppInit appInit;


    private AppInit(Application application){
        this.application=application;
        application.registerActivityLifecycleCallbacks(this);
    }
    public static void getInstance(Application application) {
        appInit = new AppInit(application);
    }

    @Override
    public void onActivityCreated(final Activity activity, Bundle savedInstanceState) {
        if(activity instanceof AppCompatActivity){
            if(activity.findViewById(R.id.toolbar)!=null){
                Toolbar toolbar=activity.findViewById(R.id.toolbar);
                ((AppCompatActivity) activity).setSupportActionBar(toolbar);
                ((AppCompatActivity) activity).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            }
        }
    }

    @Override
    public void onActivityStarted(Activity activity) {

    }

    @Override
    public void onActivityResumed(Activity activity) {

    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {

    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {

    }
}
